<template>
  <div style="z-index: 1; height: 500px; padding-top: 5px">
    <el-empty v-if="emptyVisible" :description="$t('common.empty_tip')" />
  </div>
</template>

<script>
import * as echarts from 'echarts'
import resize from '@/mixins/resize'
import { getOperatorNewActiveDeviceTrend } from '@/api/operator'

export default {
  name: 'NewActivateChart',
  mixins: [resize],
  data() {
    return {
      operator: null,
      series: [],
      chart: null,
      emptyVisible: false,
      legend: []
    }
  },
  mounted() {
    this.initData({
      dateUnit: 'Month',
      dateRange: '6',
      allModels: true,
      models: []
    })
  },
  methods: {
    initData(dataFilter) {
      this.operator = JSON.parse(localStorage.getItem('operator-info'))
      var params = {
        operatorId: this.operator.operatorId,
        oid: this.operator.oid,
        dateUnit: dataFilter.dateUnit,
        dateRange: dataFilter.dateRange,
        allModels: dataFilter.allModels,
        models: dataFilter.models
      }
      getOperatorNewActiveDeviceTrend(params)
        .then((res) => {
          this.legend = []
          res.seriesList.forEach((serie) => {
            this.legend.push(serie.name)
          })
          this.initChart(res)
        })
        .catch((e) => {
          this.$confirmError(e)
          this.emptyVisible = true
        })
    },
    initChart(data) {
      this.chart = echarts.init(this.$el)
      this.option = {
        // title: {
        //   text: this.$t('dashboard.top_10_merchants_and_active_merchants'),
        //   subtext: '纯属虚构'
        // },

        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: this.legend
        },
        calculable: true,
        xAxis: [
          {
            type: 'category',
            data: data.xaxisData
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: data.seriesList
      }
      this.chart.setOption(this.option, true)
    }
  }
}
</script>

<style>
</style>
